package com.oms.app.address.dao.impl;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.oms.app.address.dao.IAddressDAO;
import com.oms.app.address.model.Address;
import com.oms.app.sequence.service.impl.SequenceManager;
import com.oms.core.dao.impl.GeneralDAO;


/**
 * 地址表
 * controller
 * @author wtj
 * @date Sep 23, 2012  23:18:26 PM
 */

public class AddressDAOImpl extends GeneralDAO<Address, String> implements IAddressDAO {

	@Override
	public List<Address> getAddressList(HttpServletRequest request) {
		return (List<Address>) this.queryForList("getAll", "");
	}
	
	@Override
	public boolean addAddress(Address address) {
		try {
			address.setId(new Integer(SequenceManager.nextID("address")));
			address.setStatus(1);
			this.insert("insertAddress", address);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public boolean deleteAddress(String PK) {
		try {
			this.delete("deleteAddress", PK);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public Address getAddressByPK(String PK) {
		return (Address) this.queryForObject("getAddressByPK", PK);
	}

	@Override
	public boolean updateAddress(Address address) {
		try {
			this.update("updateAddress", address);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	@Override
	public boolean saveAddressRelation(Map<String, Object> map) {
		try {
			this.insert("insertAddressRelation", map);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	@Override
	public boolean deleteAddressRelation(Map<String, Object> map) {
		try {
			this.delete("deleteAddressRelation", map);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	@Override
	public List<Address> getAddressByParentId(String parentId) {
		return (List<Address>) this.queryForList("getAddressByParentId", parentId);
	}
}
